package
{
  
  import flash.display.Loader;
  import flash.display.MovieClip;
  import flash.display.Sprite;
  import flash.events.Event;
  import flash.events.MouseEvent;
  import flash.net.URLRequest;
  import flash.system.Security;
  
  public class VideoAS3 extends Sprite
  {
      
      public function VideoAS3():void {
        Security.allowDomain("*");
        Security.allowDomain("www.youtube.com");
        
        var my_player:Object;
        
        var my_loader:Loader = new Loader();
        my_loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=5"));
        my_loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
        
        // AS3
        var mc:MovieClip = new MovieClip();
        mc.graphics.beginFill(0xFF0000);
        mc.graphics.drawRect(0, 0, 100, 80);
        mc.graphics.endFill();
        mc.x = 80;
        mc.y = 240;
        addChild(mc);
        function onLoaderInit(e:Event):void{
          addChild(my_loader);
          my_player = my_loader.content;
          my_player.addEventListener("onReady", onPlayerReady);
        }
        
        function onPlayerReady(e:Event):void{
          my_player.setSize(300,240);
          my_player.cueVideoById("_OBlgSz8sSM",0);
          
          var mc3:MovieClip = new MovieClip();
          mc3.graphics.beginFill(0xFF0dd0);
          mc3.graphics.drawRect(0, 0, 300, 25);
          mc3.graphics.endFill();
          mc3.x = 0; mc3.y = 240 - mc3.height;
          my_player.addChild(mc3);
        }
        
        mc.addEventListener(MouseEvent.CLICK, playVid);
        function playVid(e:MouseEvent):void {
          my_player.playVideo();
        }
        
        var mc1:MovieClip = new MovieClip();
        mc1.graphics.beginFill(0xFF0000);
        mc1.graphics.drawRect(0, 0, 100, 80);
        mc1.graphics.endFill();
        mc1.x = 190;
        mc1.y = 240;
        addChild(mc1);
        mc1.addEventListener(MouseEvent.CLICK, pauseVid);
        function pauseVid(e:MouseEvent):void {
          my_player.pauseVideo();
        }
      }
    
  }
}